import request from '@/utils/request'
import * as x3 from "@/utils/x3request"
const publicNmae = "GESYBPC"

// 查询经销商列表
export function listGesybpc(query) {
  var objectKeys = ""
  Object.keys(query).forEach(function (key) {
    console.log(key + ': ' + query[key]);
    if (query[key] != null && !['pageNum', 'pageSize'].includes(key)) {
      objectKeys += "<key>" + key + "</key>"
      objectKeys += "<value>"
      if (['DES', 'YSQSJ', 'YBZ'].includes(key)) {
        objectKeys += "*" + query[key] + "*"
      } else {
        objectKeys += "" + query[key] + ""
      }
      objectKeys += "</value>"
    }
  });
  return x3.query(publicNmae, objectKeys, query.pageSize)
}

// 查询经销商详细
export function getGesybpc(BPCNUM) {
  return x3.read(publicNmae, "<key>BPCNUM</key>" +
    "<value>" + BPCNUM + "</value>")
  return request({
    url: '/x3base/gesybpc/' + BPCNUM,
    method: 'get'
  })
}

// 新增经销商
export function addGesybpc(data) {
  return x3.save(publicNmae, { "HEAD": data })
}

// 修改经销商
export function updateGesybpc(data) {
  return x3.modify(publicNmae,
    "<key>BPCNUM</key>" +
    "<value>" + data.BPCNUM + "</value>", { "HEAD": data })
}

// 删除经销商
export function delGesybpc(BPCNUM) {
  return x3.del(publicNmae,
    "<key>BPCNUM</key>" +
    "<value>" + BPCNUM + "</value>")
}

// 按钮操作一级办事处
export function actionGescce4(data, code) {
  return x3.actionObject(publicNmae, { "HEAD": data }, code)
}
